import java.util.Arrays;
import java.util.Scanner;
public class Test_7_16_2 {
    //返回无序数组中最长的连续序列的长度[100,4,200,1,3,2]
    //1.排序求最大连续字串
    public static void main(String[] args) {
        int[] arr = {100,4,200,1,3,2};
        System.out.println(MLS(arr));
    }
    public static int MLS(int[] arr){
        Arrays.sort(arr);
        int len = arr.length;
        int ret = 0;
        for (int i = 0; i < len; ) {
            int j = i + 1;
            int count = 1;//计数从当前i位置开始的连续子序列长度
            while(j < len){
                if (arr[j] - arr[j-1] == 1){
                    count++;
                    j++;
                }else if(arr[j] - arr[j-1] == 0){
                    j++;
                }else {
                    break;
                }
            }
            ret = Math.max(ret,count);
            i = j;
        }
        return ret;
    }
}
